﻿@{
    ViewBag.Title = "Administracion de Eventos";
}
<br />
<div id="EventoTable"></div>
@section Scripts {
    <script type="text/javascript">

        function MarcarEvento(idEvento) {
            sendObj = { idEvento: idEvento };
            _ajaxCall({
                url: GetAppURL() + "/Evento/MarcarEvento",
                data: sendObj,
                success: function (result) {
                    $('#EventoTable').jtable('updateRecord', {
                        record: {
                            idEvento: idEvento,
                            actual: true
                        },
                        clientOnly: true
                    });
                    $('#EventoTable').jtable('updateRecord', {
                        record: {
                            idEvento: result.idAnterior,
                            actual: false
                        },
                        clientOnly: true
                    });
                    $('#p-resultado').html(result.Message);
                    $('#ui-dialog-resultado').dialog('open');
                }
            });

        }
        $(document).ready(function () {
            $('#EventoTable').jtable({
                title: '@ViewBag.Title',
                paging: true,
                pageSize: 25,
                sorting: true,
                multiSorting: true,
                defaultSorting: 'nombre ASC',
                actions: {
                    listAction: '@Url.Action("EventoList", "Evento")',
                    deleteAction: '@Url.Action("DeleteEvento", "Evento")',
                    updateAction: '@Url.Action("UpdateEvento", "Evento")',
                    createAction: '@Url.Action("CreateEvento", "Evento")'
                },
                fields: {
                    idEvento: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    actual: {
                        title: '',
                        width: '2%',
                        sorting: false,
                        edit: false,
                        create: false,
                        display: function (data) {
                            var $img = $('<img src="' + GetAppURL() + '/Content/images/check.png" title="Seleccionar este evento como el evento actual" />');
                            //Abrir dialog de inscribir al hacer click
                            $img.click(function () {
                                MarcarEvento(data.record.idEvento);
                            });
                            if (data.record.actual) $img.hide();
                            return $img;
                        }
                    },
                    nombre: {
                        title: 'Nombre',
                        inputClass: 'validate[required,maxSize[50]]'
                    },
                    fechaInicio: {
                        title: 'Fecha Inicio',
                        type: 'date',
                        displayFormat: 'dd-mm-yy',
                        list: false,
                        inputClass: 'validate[required,custom[date]]'
                    },
                    fechaFin: {
                        title: 'Fecha Fin',
                        type: 'date',
                        displayFormat: 'dd-mm-yy',
                        list: false,
                        inputClass: 'validate[required,custom[date]]'
                    },
                    costoUSD: {
                        title: 'Costo USD',
                        inputClass: 'validate[required,custom[number]]'
                    },
                    costoLOC: {
                        title: 'Costo LOC',
                        inputClass: 'validate[required,custom[number]]'
                    },
                    cupo: {
                        title: 'Cupo',
                        list: false,
                        inputClass: 'validate[required,custom[integer]]'
                    },
                    costoBus: {
                        title: 'Costo Bus',
                        inputClass: 'validate[required,custom[number]]'
                    },
                    cupoHabitacion: {
                        title: 'Cupo Habitación',
                        list: false,
                        inputClass: 'validate[required,custom[integer]]'
                    },
                    observaciones: {
                        title: 'Observaciones',
                        list: false,
                        type: 'textarea',
                        inputClass: 'validate[required,maxSize[300]]'
                    },
                    idLugar: {
                        title: 'Lugar',
                        inputClass: 'validate[required]',
                        options: '@Url.Action("GetLugarOptions", "Catalogo")'
                    }
                },
                formCreated: function (event, data) {
                    data.form.validationEngine();
                },
                formSubmitting: function (event, data) {
                    return data.form.validationEngine('validate');
                },
                formClosed: function (event, data) {
                    data.form.validationEngine('hide');
                    data.form.validationEngine('detach');
                }
            });

            $('#EventoTable').jtable('load');
        });

    </script>
}

